<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no,minimal-ui">
    <title>美食每客</title>
    <link rel="icon" href="./../images/favico.ico">
    <!--不同屏幕尺寸根字体设置-->
    <script src="./../js/base.js"></script>
    <!--element-ui的样式-->
    <link rel="stylesheet" href="../../backend/plugins/element-ui/index.css"/>
    <!--引入vant样式-->
    <link rel="stylesheet" href="../styles/vant.min.css"/>
    <!-- 引入样式  -->
    <link rel="stylesheet" href="../styles/index.css"/>
    <!--本页面内容的样式-->
    <link rel="stylesheet" href="./../styles/login.css"/>
</head>
<body>
<div id="login" v-loading="loading">
    <div class="divHead">注册</div>
    <div >
        <el-input placeholder=" 请输入昵称" v-model="form.name" maxlength='20'/>
        </el-input>
        <el-input placeholder=" 请输入邮箱" v-model="form.phone" maxlength='20'/>
        </el-input>
        <el-input placeholder=" 请输入密码" v-model="form.password" maxlength='20'/>
        </el-input>
    </div>
        <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            >

            </el-option>
        </el-select>
    <div style="margin-left: 150px">
        <el-button type="primary"  @click="btnRegister">
        注册
    </el-button>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../backend/plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../backend/plugins/element-ui/index.js"></script>
<!-- 引入vant样式 -->
<script src="./../js/vant.min.js"></script>
<!-- 引入axios -->
<script src="../../backend/plugins/axios/axios.min.js"></script>
<script src="./../js/request.js"></script>
<script src="./../api/login.js"></script>
</body>
<script>
    new Vue({
        el: "#login",
        data() {
            return {
                form: {
                    name:"1",
                    phone: "1987693029@qq.com",
                    password: "1",
                    sex: '1'
                },
                options: [{
                    value: '1',
                    label: '男'
                }, {
                    value: '0',
                    label: '女'
                },]

            }
        },
        computed: {},
        created() {},
        mounted() {},
        methods: {
            // 倒计时
            timeDown() {
                if (this.clearSmsTime) {
                    clearInterval(this.clearSmsTime)
                }
                this.second = 60
                this.clearSmsTime = setInterval(() => {
                    --this.second
                    if (this.second < 1) {
                        clearInterval(this.clearSmsTime)
                        // 可以重新发送验证码
                        this.sending = true
                        this.second = 0
                    }
                }, 1000)
            },
            async btnRegister() {
                console.log(this.form)
                if (this.form.password && this.form.name&&this.form.phone ) {
                    const regex = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                    if (regex.test(this.form.phone)){
                        console.log(this.form)
                        const res = await registerApi(this.form)
                        if (res.code === 1) {
                            this.$notify({type: 'warning', message: res.msg});
                            sessionStorage.setItem("userPhone", this.form.phone)
                            window.requestAnimationFrame(() => {
                                console.log("qqqqqqqqqqq")
                                window.location.href = '/front/page/login.html'
                            })
                        } else {
                            this.$notify({type: 'warning', message: res.msg});
                        }
                    }else {
                        this.$notify({type: 'warning', message: '请输入正确邮箱'});
                    }
                    console.log(form)
                } else {
                    this.$notify({type: 'warning', message: '请输入邮箱账号'});
                }
            }
        }
    })
</script>
</html>